<?php
/**
 * Created by PhpStorm.
 * User: EDZ
 * Date: 2020/6/22
 * Time: 14:09
 */

namespace utils;


class Str
{
    public static function equalsIgnoreCase($a, $b)
    {
        $n1 = strlen($a);
        $n2 = strlen($b);
        if ($n1 != $n2) {
            return false;
        }
        for ($i = 0; $i < $n1; $i++) {
            if ((ord($a[$i]) & 0xdf) != (ord($b[$i]) & 0xdf)) {
                return false;
            }
        }
        return true;
    }

    public static function formToJson($s)
    {
        $items = explode('&', $s);
        $assoc = array();
        foreach ($items as $item) {
            $kv = explode('=', $item);
            $key = urldecode($kv[0]);
            $value = urldecode($kv[1]);
            if (is_numeric($value)) {
                if (strpos($value, ".") !== false) {
                    $value = floatval($value);
                } else {
                    $value = intval($value);
                }
            } else {
                if ($value == "null") {
                    $value = null;
                } else if ($value == "false") {
                    $value = false;
                } else if ($value == "true") {
                    $value = true;
                }
            }
            $assoc[$key] = $value;
        }
        return $assoc;
    }
}